<template>
  <div>
    <h4>配套备件</h4>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="备件编号" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.consumableBase && scope.row.consumableBase.materialNum || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="备件名称" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.consumableBase && scope.row.consumableBase.materialName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="规格型号" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.consumableBase && scope.row.consumableBase.model || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="所在仓库" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.storehouseName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="库存数量" align="center" min-width="120">
        <template slot-scope="scope">
          {{ scope.row.amount || 0 }}
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <h4>更换记录</h4>
    <el-table v-loading="loadingtwo" :data="noticeListtwo">
      <el-table-column label="备件编号" align="center" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.materialNum || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="备件名称" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.materialName || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="规格型号" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.model || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="换上日期" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.useTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="换下日期" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.removeTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="数量" align="center" min-width="130">
        <template slot-scope="scope">
          {{ scope.row.amount || 1 }}
        </template>
      </el-table-column>
      <el-table-column label="当前状态" align="center" min-width="120">
        <template slot-scope="scope">
          {{ ['使用中', '已换下'][scope.row.status] || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="换上原因" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.useReason || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="换下原因" align="center" min-width="130" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.removeReason || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="换上关联单号" align="center" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.useNum || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="换下关联单号" align="center" min-width="150">
        <template slot-scope="scope">
          {{ scope.row.removeNum || '-' }}
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="totaltwo > 0" :total="totaltwo" :page.sync="queryParamstwo.pageNum"
      :limit.sync="queryParamstwo.pageSize" @pagination="getListtwo" />
  </div>
</template>

<script>
import { getconsumablelist, getreplaceRecordlist } from "@/api/equipment/equipment.js";
export default {
  name: 'spareparts',
  props: ['rowObj'],
  data () {
    return {
      total: 0,
      loading: false,
      noticeList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'storehouseId',
        isAsc: 'desc'//倒叙
      },
      totaltwo: 0,
      loadingtwo: false,
      noticeListtwo: [],
      // 查询参数
      queryParamstwo: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'ecrRecordId',
        isAsc: 'desc'//倒叙
      },
    }
  },
  created () {
    this.getList()
    this.getListtwo()
  },
  methods: {
    async getList () {
      this.loading = true
      let params = {
        ...this.queryParams,
        'params[equipmentAccountIds]': this.rowObj.equipmentAccountId
      }
      let data = await getconsumablelist(params);
      this.total = data.total
      this.noticeList = data.data
      this.loading = false
    },
    async getListtwo () {
      this.loadingtwo = true
      let params = {
        ...this.queryParamstwo,
        equipmentAccountId: this.rowObj.equipmentAccountId
      }
      let data = await getreplaceRecordlist(params);
      this.totaltwo = data.total
      this.noticeListtwo = data.data
      this.loadingtwo = false
    }
  }
}
</script>

<style>
</style>